package com.ukao.steward.adapter;

import android.content.Context;
import android.widget.TextView;

import com.ukao.steward.R;
import com.ukao.steward.base.ListBaseAdapter;
import com.ukao.steward.base.SuperViewHolder;
import com.ukao.steward.bean.StringBean;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.DecimalUtil;

import java.util.List;

import butterknife.BindView;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class ClothingListAdapter extends ListBaseAdapter<StringBean> {




    public ClothingListAdapter(Context mContext, List<StringBean> datas) {
        super(mContext, datas);

    }
    @BindView(R.id.product_name)
    TextView name;
    @BindView(R.id.cnt)
    TextView cnt;
    @BindView(R.id.total_price)
    TextView totalPrice;
    @BindView(R.id.price)
    TextView price;

    @Override
    public int getLayoutId() {
        return R.layout.adapter_clothing_list;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        TextView price = holder.getView(R.id.price);
        TextView totalPrice = holder.getView(R.id.total_price);
        TextView cnt = holder.getView(R.id.cnt);
        TextView name = holder.getView(R.id.product_name);
        TextView discount= holder.getView(R.id.discount);

        StringBean item = mDataList.get(position);
        name.setText(CheckUtils.isEmptyString(item.getName()));
        cnt.setText( "x" + item.getCnt());/*单价 与数量*/
        String unitPrice = CheckUtils.isEmptyNumber(item.getPrice());
        price.setText("￥" + unitPrice);
        String  discounts=CheckUtils.isDiscount(item.getDiscount());
        String totalAmount="";
       String cnts=item.getCnts();
        if (CheckUtils.isEmpty(discounts)){
            discount.setText("无折扣");
            totalAmount=DecimalUtil.multiply(cnts,unitPrice);
        }else{
            discount.setText(discounts+"折");
            totalAmount=DecimalUtil.multiply(cnts,DecimalUtil.multiply(unitPrice,CheckUtils.isEmptyNumber(item.getDiscount())) );

        }
        totalPrice.setText("￥"+totalAmount);


    }
}
